var app = getApp();
var WxParse = require('../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bookdefault: app.myUlife.ulifeUrl + 'testimage/timg1.jpg',//默认图片
 
    activeIndex: 0,
    navList: [{
      name: '书籍简介',
      _id: 'sjjj',
    }, 
    {
      name: '心得体会',
      _id: 'xdth',
    },
    {
      name: '阅读点评',
      _id: 'yddp',
    },
    {
      name: '阅读排行',
      _id: 'ydph',
    }],

    startgray: '../../images/score_stars_icon_gray.png',//星级灰色
    startyellow: '../../images/score_stars_icon_yellow.png',//星级黄色
    starsy:0,
    starsn:5,

    bid: '',//书籍ID
    bookdeatil: {},//书籍详情
    xdth: [],//心得体会
    discuss: [],//阅读点评
    jfph: [],//阅读排行
    jfph1: [],
    jfph2: [],
    usid: '',
    sc: 0,//是否收藏 0否 

    showModalStatus: false,//阅读点评modal
    showxdthModalStatus: false,//心得体会modal
    showxdthplModalStatus: false,//心得体会评论modal

    discusscontent:'',//评论内容
    learncontent: '',//心得体会
    learnplcontent: '',//心得体会评论内容
    pdisid: '0',


    yddpage: { //阅读点评每页展示
      page:1,
      limit:10,
      totalpage:0
    },


    xdthpage: { //心得体会每页展示
      page: 1,
      limit: 10,
      totalpage: 0
    },

    jfphpage: { //阅读排行每页展示
      page: 1,
      limit: 20,
      totalpage: 0
    },


    imgs: [],
    upurls:[],

    learnid:'',//心得体会ID
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var usid = wx.getStorageSync('usid');
    this.setData({
      usid: usid
    })
    //获取传递的参数
    this.setData({
      bid: options.bid
    })
    //心得体会
    this.getReadlearnBybid();

    this.getBookDetail();
 
    //阅读点评（未测试）
    this.getDiscussBybid();

    //积分排行（未测试，且后台代码需要修改）
    this.getReadJfPh();

    //查询是否收藏
    this.getSfscJrsj();

  },


  getBookDetail() {
    var that = this;
    var bid = that.data.bid;
    var usid = wx.getStorageSync('usid');
    app.wxget({
      url: 'wbookdetail/getBookDetail.html',
      data: {
        bid: bid,
        usid: usid
      },
      success: function (res) {
        var bookdeatil = res.data;
        if (bookdeatil.REASON) {
          WxParse.wxParse('reason', 'html', bookdeatil.REASON, that, 5);
        } 
        that.setData({
          bookdeatil: bookdeatil,
          minpage: bookdeatil.MINNUM
        })

      }
    })
  },

  //获取心得体会
  getReadlearnBybid() {
    var that = this;
    var bid = that.data.bid;
    var page = that.data.xdthpage.page;
    var limit = that.data.xdthpage.limit;
    var usid = that.data.usid;
    app.wxget({
      url: 'wbookdetail/getReadlearnBybid.html',
      data: {
        bid: bid,
        page: page,
        usid: usid,
        limit: limit
      },
      success: function (res) {
        var list = res.data.xdth;
        var xdth =that.data.xdth;
        for (var i = 0; i < list.length;i++){
          xdth.push(list[i]);
        }
        var totalpage = res.data.totalpage;
        that.setData({
          xdth: xdth,
          "xdthpage.totalpage": totalpage
        })
      }
    })
  },


  //获取阅读点评
  getDiscussBybid() {
    var that = this;
    var bid = that.data.bid;
    var page = that.data.yddpage.page;
    var limit = that.data.yddpage.limit;
    var usid = that.data.usid;
    app.wxget({
      url: 'wbookdetail/getDiscussBybid.html',
      data: {
        bid: bid,
        page:page,
        limit: limit,
        usid:usid
      },
      success: function (res) {
        var discuss = that.data.discuss;
        var dis = res.data.discuss;
        var totalpage = res.data.totalpage;
        for (var i = 0; i < dis.length;i++){
          discuss.push(dis[i]);
        }
        that.setData({
          discuss: discuss,
          "yddpage.totalpage": totalpage
        })
      }
    })
  },


  //获取阅读排行
  getReadJfPh() {
    var that = this;
    var page = that.data.jfphpage.page;
    var limit = that.data.jfphpage.limit;
    var bid = that.data.bid;
    var nj = wx.getStorageSync('nj');
    app.wxget({
      url: 'wbookdetail/getReadJfPh.html',
      data: {
        bid: bid,
        nj: nj,
        page: page,
        limit: limit,
      },
      success: function (res) {
        var jfph = that.data.jfph;
        var jfp = res.data.jfph;
        var totalpage = res.data.totalpage;
        //前三名
        var jfph1 = that.data.jfph1;
        //除去前三名的
        var jfph2 = that.data.jfph2;

        for (var i = 0; i < jfp.length; i++) {
          jfph.push(jfp[i]);
        }
        for (var j = 0; j < jfph.length; j++) {
          var pm = parseInt(jfph[j].PM);
          if (pm <= 3) {
            jfph1.push(jfph[j]);
          } else {
            jfph2.push(jfph[j]);
          }

        }
        that.setData({
          jfph: jfph,
          jfph1: jfph1,
          jfph2: jfph2,
          "jfphpage.totalpage": totalpage
        })
      }
    })
  },

  //查询是否收藏  是否加入书架
  getSfscJrsj() {
    var that = this;
    var bid = that.data.bid;
    var usid = that.data.usid;
    app.wxget({
      url: 'wbookdetail/getSfscJrsj.html',
      data: {
        bid: bid,
        usid: usid
      },
      success: function (res) {
        that.setData({
          sc: res.data.SC
        })
      }
    })
  },

  //切换显示
  changShow(e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    that.setData({
      activeIndex: index
    })
  },

  //当图片错误时  替换默认图片
  errorFm: function (e) {
    if (e.type == "error") {
      var bookdeatil = this.data.bookdeatil    　　　　　　　//将图片列表数据绑定到变量
      bookdeatil.FM = this.data.bookdefault //错误图片替换为默认图片
      this.setData({
        bookdeatil: bookdeatil
      })
    }
  },

  //我要收藏
  collectionbook(e) {
    var that = this;
    var bid = that.data.bid;
    var usid = wx.getStorageSync('usid');
    if (!usid) {
      wx.reLaunch({
        url: '../../pages/login/login'
      })
      return;
    }
    app.wxget({
      url: 'wbookdetail/collectionbook.html',
      data: {
        bid: bid,
        usid: usid
      },
      success: function (res) {
        if (res.data) {
          that.setData({
            sc: 1,
          })
          wx.showModal({
            title: '成功',
            content: '收藏成功!',
            showCancel: !1,
          })
        } else {
          wx.showModal({
            title: '友情提示',
            content: '收藏失败!',
            showCancel: !1,
          })
        }
      }
    })
  },


  //取消收藏
  cancelcollectionbook(e) {
    var that = this;
    var bid = that.data.bid;
    var usid = wx.getStorageSync('usid');
    if (!usid) {
      wx.reLaunch({
        url: '../../pages/index/index'
      })
      return;
    }
    app.wxget({
      url: 'wbookdetail/cancelcollectionbook.html',
      data: {
        bid: bid,
        usid: usid
      },
      success: function (res) {
        if (res.data) {
          that.setData({
            sc: 0,
          })
          wx.showModal({
            title: '成功',
            content: '取消成功!',
            showCancel: !1,
          })
        } else {
          wx.showModal({
            title: '友情提示',
            content: '取消失败!',
            showCancel: !1,
          })
        }
      }
    })
  },


  //打开阅读点评modal
  powerDrawer(e) {
    var usid = wx.getStorageSync('usid');
    if (!usid) {
      wx.reLaunch({
        url: '../../pages/login/login'
      })
      return;
    }
    var currentStatu = e.currentTarget.dataset.statu;
    this.util(currentStatu);
  },


  //点击灰色星星
  addstar(e) {
    var stars = e.currentTarget.dataset.stars;
    var starsy = this.data.starsy;//黄色的星星
    var starsn = this.data.starsn;//灰色的星星 
    var yellow = parseInt(starsy) + parseInt(stars)+1;
    var grew = 5 - parseInt(yellow) ;
    this.setData({
      starsy: yellow,
      starsn: grew
    })
  },

 //点击黄色星星
  substar(e) {
    var stars = e.currentTarget.dataset.stars;
    var yellow = stars;
    var grew = 5 - parseInt(stars);
    this.setData({
      starsy: yellow,
      starsn: grew
    })
  },

  //获取评论
  getdiscuss(e) {
    this.setData({
      discusscontent: e.detail.value
    })
  },




  //保存评论数据
  sendDiscuss(e) {
    var that = this;
    var bid = that.data.bid;
    var usid = wx.getStorageSync('usid');
    if (!usid) {
      wx.reLaunch({
        url: '../../pages/login/login'
      })
      return;
    }
    var username = wx.getStorageSync('name');
    var discuss = that.data.discusscontent;
    if (discuss == "" || discuss == null || discuss == undefined){
      wx.showModal({
        title: '失败',
        content: '请输入评论内容!',
        showCancel: !1,
      });
      return;
    }
    var pdisid = that.data.pdisid;
    app.wxget({
      url: 'wdsj/sendDiscuss.html',
      data: {
        bid: bid,
        discuss: discuss,
        usid: usid,
        username: username,
        pdisid: pdisid,
      },
      success: function (res) {
        console.log(res)
        if (res.data) {
          if(res.data.result){
            wx.showModal({
              title: '成功',
              content: '评论成功!',
              showCancel: !1,
            });
            that.setData({
              discuss: [],
              yddpage:{ //阅读点评每页展示
                page: 1,
                limit: 10,
                totalpage: 0
              },
            })
            that.getDiscussBybid();
          }else{
            wx.showModal({
              title: '错误！',
              content: res.data.msg,
              showCancel: !1,
            })
          }
          that.util("close");
        } else {
          wx.showModal({
            title: '友情提示',
            content: '评论失败!',
            showCancel: !1,
          })
        }
      }
    })
  },




  //点赞
  discussthumbsupAdd(e) {
    var that = this;
    var disid = e.currentTarget.dataset.disid;
    var index = e.currentTarget.dataset.index;
    var usid = wx.getStorageSync('usid');
    if (!usid) {
      wx.reLaunch({
        url: '../../pages/login/login'
      })
      return;
    } 
    app.wxget({
      url: 'wdsj/discussthumbsupAdd.html',
      data: {
        disid: disid,
        usid: usid
      },
      success: function (res) {
        if (res.data) {
          wx.showToast({
            title: '成功',
            icon: 'success',
            duration: 2000
          }) 
          var discuss = that.data.discuss;
          discuss[index].DZRS = parseInt(discuss[index].DZRS)+1;
          discuss[index].SFDZ=1;
          that.setData({
            discuss: discuss
          }) 
        } else {
          wx.showToast({
            title: '失败',
            icon: 'fail',
            duration: 2000
          })  
        }
      }
    })
  },

  //取消点赞
  discussthumbsupSub(e) {
    var that = this;
    var disid = e.currentTarget.dataset.disid;
    var usid = wx.getStorageSync('usid');
    if (!usid) {
      wx.reLaunch({
        url: '../../pages/login/login'
      })
      return;
    }
    var index = e.currentTarget.dataset.index;
    app.wxget({
      url: 'wdsj/discussthumbsupSub.html',
      data: {
        disid: disid,
        usid: usid
      },
      success: function (res) {
        if (res.data) {
          wx.showToast({
            title: '取消成功',
            icon: 'success',
            duration: 2000
          })
          var discuss = that.data.discuss;
          discuss[index].DZRS = parseInt(discuss[index].DZRS) - 1;
          discuss[index].SFDZ = 0;
          that.setData({
            discuss: discuss
          }) 
        } else {
          wx.showToast({
            title: '取消失败',
            icon: 'fail',
            duration: 2000
          })
        }
      }
    })
  },


  //打开对阅读点评进行评论
  nextpl(e) {
    var currentStatu = e.currentTarget.dataset.statu;
    var pdisid = e.currentTarget.dataset.disid;
    this.setData({
      pdisid: pdisid,
    })
    this.util(currentStatu);
  },

  //更多评论
  moreDicussBybid(e) {
    var page=this.data.yddpage.page;
    this.setData({
      "yddpage.page": parseInt(page)+1
    })
    this.getDiscussBybid();
  },


  //更多内部评论
  moreDicussPlByDisid(e) {
    var page = e.currentTarget.dataset.page;
    var pdisid = e.currentTarget.dataset.pdisid;
    var index = e.currentTarget.dataset.index;
    var discuss = this.data.discuss;
    var npage = parseInt(page)+1;
    discuss[index].page = npage;
    var list = discuss[index].list;
    var that=this;
    app.wxget({
      url: 'wdsj/moreDicussPlByDisid.html',
      data: {
        pdisid: pdisid,
        page: npage
      },
      success: function (res) {
        for(var m=0;m<res.data.length;m++){
          list.push(res.data[m]);
        }
        discuss[index].list = list;
        that.setData({
          discuss: discuss
        })
      }
    })

  },

  //心得体会
  xdthShow(e) {
    var currentStatu = e.currentTarget.dataset.statu;
    this.openxdh(currentStatu);
  },


  //获取心得体会内容
  getlearncontent(e) {
    this.setData({
      learncontent: e.detail.value
    })
  },
 


  //心得体会打开
  openxdh(currentStatu) {
    /* 动画部分 */
    // 第1步：创建动画实例   
    var animation = wx.createAnimation({
      duration: 200, //动画时长  
      timingFunction: "linear", //线性  
      delay: 0 //0则不延迟  
    });

    // 第2步：这个动画实例赋给当前的动画实例  
    this.animation = animation;

    // 第3步：执行第一组动画  
    animation.opacity(0).rotateX(-100).step();

    // 第4步：导出动画对象赋给数据对象储存  
    this.setData({
      animationData: animation.export()
    })

    // 第5步：设置定时器到指定时候后，执行第二组动画  
    setTimeout(function () {
      // 执行第二组动画  
      animation.opacity(1).rotateX(0).step();
      // 给数据对象储存的第一组动画，更替为执行完第二组动画的动画对象  
      this.setData({
        animationData: animation
      })
      //关闭  
      if (currentStatu == "close") {
        this.setData({
          showxdthModalStatus: false
        });
      }
    }.bind(this), 200)
    // 显示  
    if (currentStatu == "open") {
      this.setData({
        showxdthModalStatus: true
      });
    }
  },



  //上传图片
  uploadimage: function () {
    var that = this;
    wx.chooseImage({
      count: 4, //张数， 默认9
      sizeType: ['compressed'], //建议压缩图
      sourceType: ['album', 'camera'], // 来源是相册、相机
      success: function (res) {
        var imgs = that.data.imgs;
        for (var i = 0; i < res.tempFilePaths.length; i++) {
          imgs.push(res.tempFilePaths[i]);
        }
        that.setData({
          imgs: imgs
        })
      }
    });
  },

  checkReadlearn: function (e) {
    var that = this;
    var bid = that.data.bid;
    var usid = wx.getStorageSync('usid');
    if (!usid) {
      wx.reLaunch({
        url: '../../pages/login/login'
      })
      return;
    }
    app.wxget({
      url: 'wdsj/checkReadlearn.html',
      data: {
        bid: bid,
        usid: usid
      },
      success: function (res) {
        if (res.data) {
          that.openxdh("open");
        } else {
          wx.showModal({
            title: '友情提示',
            content: '你已经写了心得体会，不能重复写!',
            showCancel: !1,
          })
          return;
        }
      }
    })

  },

  //提交心得体会
  sendReadlearn: function (e) {
    var that = this;
    var usid = wx.getStorageSync('usid');
    if (!usid) {
      wx.reLaunch({
        url: '../../pages/login/login'
      })
      return;
    }

    var learncontent = that.data.learncontent;
    var imgs = that.data.imgs;
    var bid = that.data.bid;

    var learncontent = this.data.learncontent;
    if (learncontent == '' && imgs.length <= 0) {
      wx.showModal({
        title: '友情提示',
        content: '心得体会或图片请选择其中一个上传!',
        showCancel: !1,
      })
      return;
    }

    //先上传图片
    if (imgs.length > 0) {
      wx.showLoading({
        title: '保存中',
      })
      that.setData({
        disabled: true,
        loading: true
      })
      //先上传图片
      that.uploadBookurl();
    } else {
      that.oksaveReadlearn();
    }
  },

  //提交心得体会图片
  uploadBookurl: function () {
    var that = this;
    var imgs = this.data.imgs;
    var upurls = this.data.upurls;
    const uploadTask = app.wxupload({
      url: 'upload/uploadXdthurl.html',
      filePath: imgs[0],
      name: 'file',
      formData: {},
      success: function (res) {
        var img = JSON.parse(res.data);
        var url = img.urls;
        upurls.push(url); 
        that.setData({
          upurls: upurls
        });
        that.data.imgs.splice(0, 1);
        if (that.data.imgs.length > 0) {
          that.uploadBookurl();
        } else {
          that.oksaveReadlearn();
        }
      }
    })
  },

  //保存心得体会
  oksaveReadlearn(e) {
    var that = this;
    var learncontent = that.data.learncontent;
    var upurls = that.data.upurls;
    var bid = that.data.bid;
    var usid = that.data.usid;
    var username = wx.getStorageSync('name');
    app.wxget({
      url: 'wdsj/saveReadlearn.html',
      data: {
        learncontent: learncontent,
        upurls: upurls,
        bid: bid,
        usid: usid,
        username: username,
      },
      success: function (res) {
        if (res.data) {
          if (res.data.result) {
            wx.showModal({
              title: '错误',
              content: res.data.msg,
              showCancel: !1,
            });
            return;
          }
          wx.showModal({
            title: '成功',
            content: '提交成功!',
            showCancel: !1,
          });

          wx.hideLoading();
          that.openxdh('close');
          that.setData({
            xdth: [],
            xdthpage: { //阅读点评每页展示
              page: 1,
              limit: 10,
              totalpage: 0
            },
          })
          
          that.getReadlearnBybid();
        } else {
          wx.showModal({
            title: '友情提示',
            content: '提交失败!',
            showCancel: !1,
          })
        }
      }
    })
  },


  //更多心得体会
  moreXdthBybid(e) {
    var page = this.data.xdthpage.page;
    this.setData({
      "xdthpage.page": parseInt(page) + 1
    })
    this.getReadlearnBybid();
  },


  //更多心得体会评论
  moreReadlearnPlByid(e) {
    var page = e.currentTarget.dataset.page;
    var learnid = e.currentTarget.dataset.learnid;
    var index = e.currentTarget.dataset.index;
    var xdth = this.data.xdth;
    var npage = parseInt(page) + 1; 
    xdth[index].page = npage;
    var pls = xdth[index].pls;
    var that = this;
    app.wxget({
      url: 'wdsj/moreReadlearnPlByid.html',
      data: {
        learnid: learnid,
        page: npage
      },
      success: function (res) {
        for (var m = 0; m < res.data.length; m++) {
          pls.push(res.data[m]);
        }
        xdth[index].pls = pls;
        that.setData({
          xdth: xdth
        })
      }
    })
  },


  //打开心得体会评论
  xdthplShowId(e) {
    var currentStatu = e.currentTarget.dataset.statu;
    var learnid = e.currentTarget.dataset.learnid;
    this.setData({
      learnid: learnid,
      starsy: 0,
      starsn: 5,
    })

    this.openxdthpl(currentStatu);
  },

  //打开心得体会评论
  xdthplHidden(e) {
    wx.showModal({
      title: '友情提示',
      content: '你今天评论打星了，不需要重复评论!',
      showCancel: !1,
    })
  },

  //心得体会评论打开
  xdthplShow(e) {
    var currentStatu = e.currentTarget.dataset.statu;
    this.openxdthpl(currentStatu);
  },




  //打开心得体会评论
  openxdthpl(currentStatu) {
    /* 动画部分 */
    // 第1步：创建动画实例   
    var animation = wx.createAnimation({
      duration: 200, //动画时长  
      timingFunction: "linear", //线性  
      delay: 0 //0则不延迟  
    });

    // 第2步：这个动画实例赋给当前的动画实例  
    this.animation = animation;

    // 第3步：执行第一组动画  
    animation.opacity(0).rotateX(-100).step();

    // 第4步：导出动画对象赋给数据对象储存  
    this.setData({
      animationData: animation.export()
    })

    // 第5步：设置定时器到指定时候后，执行第二组动画  
    setTimeout(function () {
      // 执行第二组动画  
      animation.opacity(1).rotateX(0).step();
      // 给数据对象储存的第一组动画，更替为执行完第二组动画的动画对象  
      this.setData({
        animationData: animation
      })
      //关闭  
      if (currentStatu == "close") {
        this.setData({
          showxdthplModalStatus: false
        });
      }
    }.bind(this), 200)
    // 显示  
    if (currentStatu == "open") {
      this.setData({
        showxdthplModalStatus: true
      });
    }
  },



  //心得体会评论内容
  getlearnplcontent(e) {
    this.setData({
      learnplcontent: e.detail.value
    })
  },

  
  //心得体会评论内容保存
  saveReadlearnpl(e) {
    var that = this;
    var learnid = that.data.learnid;
    var plcontent = that.data.learnplcontent;
    var usid = that.data.usid;
    var username = wx.getStorageSync('name');
    var pstar = that.data.starsy; 
    var jf = parseInt(pstar)*0.5;

    app.wxget({
      url: 'wdsj/saveReadlearnpl.html',
      data: {
        learnid: learnid,
        plcontent: plcontent,
        usid: usid,
        username: username,
        pstar: pstar,
        jf: jf
      },
      success: function (res) {
        if (res.data) {
          wx.showModal({
            title: '成功',
            content: '提交成功!',
            showCancel: !1,
          });
          that.openxdthpl("close");
          that.setData({
            xdth: [],
            xdthpage: { //阅读点评每页展示
              page: 1,
              limit: 10,
              totalpage: 0
            },
          })
          that.getReadlearnBybid();
        } else {
          wx.showModal({
            title: '友情提示',
            content: '提交失败!',
            showCancel: !1,
          })
        }
      }
    })
  },



  util(currentStatu) {
    /* 动画部分 */
    // 第1步：创建动画实例   
    var animation = wx.createAnimation({
      duration: 200, //动画时长  
      timingFunction: "linear", //线性  
      delay: 0 //0则不延迟  
    });

    // 第2步：这个动画实例赋给当前的动画实例  
    this.animation = animation;

    // 第3步：执行第一组动画  
    animation.opacity(0).rotateX(-100).step();

    // 第4步：导出动画对象赋给数据对象储存  
    this.setData({
      animationData: animation.export()
    })

    // 第5步：设置定时器到指定时候后，执行第二组动画  
    setTimeout(function () {
      // 执行第二组动画  
      animation.opacity(1).rotateX(0).step();
      // 给数据对象储存的第一组动画，更替为执行完第二组动画的动画对象  
      this.setData({
        animationData: animation
      })
      //关闭  
      if (currentStatu == "close") {
        this.setData({
          showModalStatus: false
        });
      }
    }.bind(this), 200)
    // 显示  
    if (currentStatu == "open") {
      this.setData({
        showModalStatus: true
      });
    }
  },




  //删除图片
  delImage: function (e) {
    var that = this;
    var imgs = that.data.imgs;
    var cuindex = e.target.dataset.index;
    imgs.splice(cuindex, 1);
    that.setData({
      imgs: imgs
    })
  },

  //预览图片
  viewimage: function (e) {
    var cuindex = e.target.dataset.index;
    var that = this;
    var urls = that.data.imgs;
    wx.previewImage({
      current: urls[cuindex], // 当前显示图片的http链接
      urls: urls // 需要预览的图片http链接列表
    })
  },

  //预览心得体会图片
  viewimagepj: function (e) {
    var cuindex = e.target.dataset.index;
    var that = this;
    var xdth =this.data.xdth;
    var pics = xdth[cuindex].pics;
    var urls = [];
    for (var i = 0; i < pics.length;i++){
      urls.push(pics[i].PICURL);
    }

    wx.previewImage({
      current: urls[cuindex], // 当前显示图片的http链接
      urls: urls // 需要预览的图片http链接列表
    })
  },

  //开始阅读打卡
  beginReading() {
    var bid = this.data.bid;
    wx.navigateTo({
      url: '../../pages/bookydjl/bookydjl?bid=' + bid
    })
  },

  //打卡完成  开始答题
  beginQuestion() {
    var that=this;
    var bid = this.data.bid;
    //1.查询本书是否上传题目
    app.wxget({
      url: 'question/getQuestionBybid.html',
      data: {
        bid: bid
      },
      success: function (res) {
        //2 .查询我是否完成答题  如果没有  则答题  如果有  则跳转到答题成功页面
        if (res.data.length>0){
           that.getMyAnswerBybid();
        }else{
          wx.showModal({
            title: '友情提示',
            content: '本书没有上传任何需要回答的问题!',
            showCancel: !1,
          })
          return;
        }
      }
    })
  },

  getMyAnswerBybid(){
    var bid = this.data.bid;
    var usid = wx.getStorageSync('usid');
    var that=this;
    var bookname = that.data.bookdeatil.BOOKNAME;
    app.wxget({
      url: 'question/getMyAnswerBybid.html',
      data: {
        bid: bid,
        usid:usid
      },
      success: function (res) {
        //2 .查询我是否完成答题  如果没有  则答题  如果有  则跳转到答题成功页面
        if (res.data.length > 0) {
          //跳转到答题成功页面
          wx.redirectTo({
            url: '../../pages/hdcg/hdcg?bid=' + that.data.bid
          })
        } else {
          //跳转到答题页面
          wx.navigateTo({
            url: '../../pages/bookquestion/question/question?bid=' + bid + "&bookname=" + bookname
          })
        }
      }
    })

  }


}) 
